﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectQuaDep.Controls
{
    public partial class NewsHome : System.Web.UI.UserControl
    {
        private string sFormat = @"<h2>
            <a href=""{0}"">{1}</a></h2>
        <a href=""{0}"">
            <img src=""{2}"" /></a>
        <p>
           {3}
        </p>";
        private string sFormatSlide = @"<div>
                <h2>
                    <a href=""{0}"">{1}</a></h2>
                <a href=""{0}"">
                    <img src=""{2}"" /></a>
                <p>
                    {3}
                </p>
            </div>";
        private string TopHome = "5";
        private string newsIDTop = "1";
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dtTopHome = BO.News.NewsBO.GetDetailNewsBO(newsIDTop);
            if(dtTopHome!=null && dtTopHome.Rows.Count>0)
            {
                DataRow dr = dtTopHome.Rows[0];
                string title = dr[BO.Const.tbNews.Title].ToString();
                string sapo = dr[BO.Const.tbNews.Sapo].ToString();
                string NewsID = dr[BO.Const.tbNews.id].ToString();
                string url = BO.ReWriteUrl.BuildLink.BuildLinkNews(NewsID);
                string Images = BO.Utils.CropImage(367, 166, dr[BO.Const.tbNews.Avatar].ToString());
                ltNewsTopHome.Text = string.Format(sFormat, url, title, Images, sapo);
            }
            //
            DataTable dtSlide = BO.News.NewsBO.GetNewsFocusBO(TopHome);
            if (dtSlide != null && dtSlide.Rows.Count > 0)
            {
                for (int i = 0; i < dtSlide.Rows.Count; i++)
                {
                    DataRow dr = dtSlide.Rows[i];
                    string title = dr[BO.Const.tbNews.Title].ToString();
                    string sapo = BO.Utils.getSubStringNice(dr[BO.Const.tbNews.Sapo].ToString(),120);
                    string NewsID = dr[BO.Const.tbNews.id].ToString();
                    string url = BO.ReWriteUrl.BuildLink.BuildLinkNews(NewsID);
                    string Images = BO.Utils.CropImage(242, 242, dr[BO.Const.tbNews.Avatar].ToString());
                    ltNewsFocus.Text += string.Format(sFormatSlide, url, title, Images, sapo);
                }
                
            }
        }
    }
}